// pages/Home/addversion/addversion.js
var app = getApp();
var ikz = require('../../Common/tools.js');
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var id = options.id;
    this.setData({
      id: id,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  //图片点击事件
  showImg: function (event) {
    var src = event.currentTarget.dataset.src; //获取data-src
    var imgList = this.data.all_img; //获取data-list
    //图片预览
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: imgList // 需要预览的图片http链接列表
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    ikz.over(this);
    var that = this;
    var id = that.data.id;
    var data = {
      id: id,
    }
    var path = 'Index/addversion';
    ikz.request(path, data, false, (res) => {
      console.log(res.data);
      if (res.data.status == 'success') {
        var advert_info = res.data.advert_info;
        advert_info.html_content = WxParse.wxParse('article', 'html', advert_info.advert_content, that, 0);
        var all_img = advert_info.advert_img;
        that.setData({
          advert_info: advert_info,
          all_img: all_img,
        })
        ikz.hide(that);
      } else {
        wx.showModal({
          title: '加载失败',
          content: '请稍后重试！',
          showCancel: false
        })
      }

    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})